/*
 * Trace.cpp
 *
 *  Created on: 7 Dec 2010
 *      Author: kn308
 */

#include <MAlice/Trace.h>

static Trace* gTrace = new Trace();

Trace* Trace::getTrace()
{
	return gTrace;
}

Trace::Trace()
{
}

Trace::~Trace()
{
}

void Trace::push(TraceNode* node)
{
	mNodes.push_back(node);
}

void Trace::pop()
{
	if (!std::uncaught_exception())
	{
		mNodes.pop_back();
	}
}

void Trace::dump(std::ostream& os)
{
	int i = 0;
	for (vector<TraceNode*>::iterator node = mNodes.begin(), e = mNodes.end(); node != e; node++)
	{
		if (TraceNode* trace = *node)
		{
			if (node == mNodes.begin())
				os << "After tripping Alice examined her dump:" << endl;
			else
				os << "|" << endl;
			trace->print(os, i++);
		}
		else
		{
			for (int j = i; j; j--)
				os << "--";
			os << "[Trace Not Available]" << endl;
		}

	}
}
